﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace CCodeTreeLib
{
    public class CodeTreeCSharpProvider
    {
        CCodeTree _tree;
        private Stream _stream;

        public Stream Stream 
        {
            get { return _stream; }
            set { _stream = value; }
        }

        public virtual void Dump(CCodeTree tree, Stream stream)
        {
            _tree = tree;
            _stream = stream;

            WriteLine(_tree.ToString());
            _stream.Flush();
        }

        protected void WriteLine(string code, bool indent = true)
        {
            Write(Encoding.ASCII.GetBytes(code + "\r\n"));
        }

        protected void Write(string code, bool indent = false)
        {
            Write(Encoding.ASCII.GetBytes(code));
        }

        void Write(byte[] bytes)
        {
            _stream.Write(bytes, 0, bytes.Length);
        }

    }
}
